package logic

import (
	"context"
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"
	"doctor-medicine-system/model/mysql"
	"errors"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 药品添加
func (l *GoodsAddLogic) GoodsAdd(in *doctorrpc.GoodsAddRequest) (*doctorrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line

	goods := &mysql.Goods{
		Name:    in.Name,
		Types:   in.Types,
		Froms:   in.Froms,
		Comfort: in.Comfort,
		Num:     int(in.Num),
		Top:     in.Top,
		UserId:  int(in.UserId),
	}

	err := goods.GoodsAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("药品添加失败")
	}

	return &doctorrpc.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
